package com.link2room.optimus.util;

import com.link2room.optimus.constant.PricePoolConstant;

import java.math.BigDecimal;

/**
 * Created by sss on 2016/9/18.
 */
public final class PricePoolUtil {

    public static final BigDecimal getPriceResult(BigDecimal basePrice,String carryType,BigDecimal multiplyValue,BigDecimal addValue){
        if(basePrice.compareTo(new BigDecimal(-1000))!=0){
            if(multiplyValue!=null){
                basePrice= basePrice.multiply(multiplyValue);
            }
            if(addValue!=null){
                basePrice= basePrice.add(addValue);
            }
        }
        switch (carryType){
            case PricePoolConstant.CARRYTYPE.CEIL:
                basePrice=basePrice.setScale(0, BigDecimal.ROUND_CEILING);
                return basePrice;
            case PricePoolConstant.CARRYTYPE.FLOOR:
                basePrice=basePrice.setScale(0, BigDecimal.ROUND_FLOOR);
                return basePrice;
            case PricePoolConstant.CARRYTYPE.ROUND:
                basePrice=basePrice.setScale(0, BigDecimal.ROUND_HALF_UP);
                return basePrice;
            default:
                return basePrice;
        }
    }

    public static final BigDecimal getPmsPriceResult(BigDecimal basePrice,String carryType,BigDecimal multiplyValue,BigDecimal addValue,BigDecimal comm){
        if(basePrice.compareTo(new BigDecimal(-1000))!=0){
            if(multiplyValue!=null){
                basePrice= basePrice.multiply(multiplyValue.subtract(comm));
            }
            if(addValue!=null){
                basePrice= basePrice.add(addValue);
            }
        }
        switch (carryType){
            case PricePoolConstant.CARRYTYPE.CEIL:
                basePrice=basePrice.setScale(0, BigDecimal.ROUND_CEILING);
                return basePrice;
            case PricePoolConstant.CARRYTYPE.FLOOR:
                basePrice=basePrice.setScale(0, BigDecimal.ROUND_FLOOR);
                return basePrice;
            case PricePoolConstant.CARRYTYPE.ROUND:
                basePrice=basePrice.setScale(0, BigDecimal.ROUND_HALF_UP);
                return basePrice;
            default:
                return basePrice;
        }
    }
}
